<template>
    <NConfigProvider
        class="h-100"
        :locale="zhCN"
        :theme="getDarkTheme"
        :theme-overrides="getThemeOverrides"
        :date-locale="dateZhCN">
        <NNotificationProvider class="h-100">
            <NMessageProvider class="h-100">
                <Navigation>
                    <router-view/>
                </Navigation>
            </NMessageProvider>
        </NNotificationProvider>
    </NConfigProvider>
</template>

<script lang="ts">
import {computed, defineComponent, onBeforeUnmount, onMounted,} from "vue"
import {
    darkTheme,
    dateZhCN,
    NConfigProvider,
    NLayout,
    NLayoutSider,
    NMessageProvider,
    NNotificationProvider,
    NSpace,
    zhCN,
} from 'naive-ui';
import {BookOutline as BookIcon, HomeOutline as HomeIcon, PersonOutline as PersonIcon} from '@vicons/ionicons5'
import {useDesignSettingStore} from "./store/modules/designSetting";
import {lighten} from "./utils";
import Navigation from "frontend/src/components/navigation/index.vue";
import VConsole from 'vconsole';

export default defineComponent({
    components: {
        NConfigProvider,
        NSpace,
        NLayout,
        NLayoutSider,
        BookIcon,
        PersonIcon,
        HomeIcon,
        Navigation,
        NNotificationProvider,
        NMessageProvider
    },
    setup() {
        const designStore = useDesignSettingStore();
        /**
         * @type import('naive-ui').GlobalThemeOverrides
         */
        const getThemeOverrides = computed(() => {
            const appTheme = designStore.appTheme;
            const lightenStr = lighten(designStore.appTheme, 6);
            return {
                common: {
                    primaryColor: appTheme,
                    primaryColorHover: lightenStr,
                    primaryColorPressed: lightenStr,
                },
                LoadingBar: {
                    colorLoading: appTheme,
                },
            };
        });

        const getDarkTheme = computed(() => (designStore.darkTheme ? darkTheme : undefined));

        let vConsole = new VConsole({

        });
        vConsole.hideSwitch()
        vConsole.hide()
        let showVConsole = false

        function hiddenFeatureListener(e: KeyboardEvent) {
            let key = e.key
            let ctrlKey = e.ctrlKey || e.metaKey;
            let altKey = e.altKey
            let shiftKey = e.shiftKey

            if (ctrlKey && altKey && key.toUpperCase() === "X") {
                if(showVConsole){
                    showVConsole = false
                    vConsole.hideSwitch();
                    vConsole.hide()
                } else {
                    showVConsole = true
                    vConsole.showSwitch();
                    vConsole.show()
                }
                return false;
            }
        }

        onMounted(() => {
            window.addEventListener("keydown", hiddenFeatureListener)
        })

        onBeforeUnmount(() => {
            window.removeEventListener("keydown", hiddenFeatureListener)
        })


        return {
            zhCN,
            dateZhCN,
            getDarkTheme,
            getThemeOverrides,
        }
    },
})
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: left;
    color: #2c3e50;
    margin-top: 0;
    height: 100vh
}
</style>
<style lang="less">
@import 'styles/index.less';
</style>
